<template>
<div class="selectd" @mouseenter="onMouseOver" @mouseleave="onMouseOut">
    <div class="selectd-detail"  ref="selectDetail" >
        <div class="selectd-detail-input">
            <!-- 选中后的内容 -->
            <div class="selectd-text ft-18">
              <span class="selectd-rad-h9 mr5"></span>
              <span>{{ curText }}</span>
            </div>
            <!-- 切换图标 -->
            <div>
              <span class="selectd-color mr5 ft-14">切换</span>
              <span class="selectd-trun t-c" :class="{'trun-active':isListShow}">
                <span class="iconfont icon-sand-turn ft-14 t-c"></span>
              </span>
            </div>
        </div>
    </div>
    <!-- 下拉框列表 -->
    <transition name="selectd-down" >
        <div class="selectd-list" v-show="isListShow" ref="dropDown">
            <div class="selectd-triangle"></div>
            <ul class="selectd-option-list">
                <li class="selectd-option t-l ft-14" :class="{'active-selectd': curIndex === item.dicValue}"  @click="currentSelect(item)" v-for="item in platList" :key="item.dicName">
                  <span class="selectd-rad-h5 mr5"></span>
                  <span class="selectd-option-wd">{{ item.dicName }}</span>
                </li>
            </ul>
        </div>
    </transition>
</div>
</template>
<script>
export default {
  name: 'selectd',
  props: {
    platList: Array,
    chosePlatIndex: {
      type: String,
      default: '-1'
    },
    platText: String
  },
  components: {},
  data() {
    return {
      curIndex: this.chosePlatIndex,
      curText: this.platText,
      isListShow: false
    }
  },
  created() {
  },
  mounted() {
  },
  computed: {
  },
  methods: {
    onMouseOver () {
      this.isListShow = true
    },
    onMouseOut () {
      this.isListShow = false
    },
    async currentSelect(item) {
      this.curText = item.dicName
      this.curIndex = item.dicValue
      this.$emit('changeMenu', item.dicValue)
    }
  }
}
</script>
<style lang="less" scoped>
.selectd {
  height: 53px;
  width: 314px;
  padding: 0 20px;
  line-height: 53px;
  position: relative;
  cursor: pointer;
}
.selectd-detail {
  width: 100%;
  height: 100%;
  border-radius: 5px;
}
.selectd-detail-input {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 53px;
  line-height: 53px;
}
.selectd-text {
  width: 75%;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color:#333;
}
.selectd-color{
  color:#999999;
}
.selectd-trun{
  display: inline-block;
  width: 30px;
  height: 30px;
  line-height: 30px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 2px 5px 8px #e2e8f1;
}
.selectd-trun:hover{
  background: #00A8F4;
  color:#fff;
}
.trun-active{
  background: #00A8F4;
  color:#fff;
}
.selectd-list {
  margin-top: 10px;
  z-index: 800;
  position: absolute;
  background-color: #fff;
  top:41px;
  right: 15px;
  box-shadow: 0px 0px 5px 0px rgba(54, 92, 158, 0.28);
  border-radius: 5px;
}
.selectd-option-list {
  border-radius: 5px;
  border: 1px solid #e4e7ed;
  width: 160px;
  padding: 13px 0px;
  background-color: #fff;
}
.selectd-triangle {
  width: 14px;
  height: 7px;
  position: absolute;
  top:-6px;
  right:14px;
}
.selectd-triangle::before {
  position: absolute;
  content: '';
  left: 0px;
  width: 0;
  height: 0;
  border-top: 0px solid transparent;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 6px solid #ebeef5;
}
.selectd-triangle::after {
  position: absolute;
  left: 2px;
  top: 2px;
  content: '';
  width: 0;
  height: 0;
  border-top: 0px solid transparent;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 7px solid #fff;
}
.selectd-down-enter {
  opacity: 0;
  transform: translate(0px, 10px);
}
.selectd-down-leave-to {
  opacity: 0;
  transform: translate(0px, 10px);
}
.selectd-down-enter-active {
  transition: all 0.5s ease-in;
}
.selectd-down-leave-active {
  transition: all 0.5s ease;
}

.selectd-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
  cursor: pointer;
  margin: 0 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  height: 30px;
  line-height: 30px;
  padding: 0 13px;
  color:#333;
}
.selectd-option:hover {
  color: #00A8F4 ;
  font-weight: 700;
  background-color: #E8F4FF;
}
.selectd-rad-h5{
  opacity: 0;
}
.selectd-option-wd{
  width:123px;
}
.active-selectd {
  color: #00A8F4;
  .selectd-rad-h5{
    opacity: 1;
  }
}
</style>
